<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('晶棒托入库')"/>
    <style>
        [v-cloak] {
            display: none;
        }
        .el-date-editor.el-input, .el-date-editor.el-input__inner {
            width: 200px!important;
        }
        .el-input__icon {
            line-height: 0!important;
        }
        .tag {
            display: inline-block;
            padding: 0 5px;
            line-height: 22px;
            color: #FFFFFF;
            border-radius: 3px;
        }
        .el-tag.el-tag--info {
            color: #000!important;
        }
    </style>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li v-if="checkedSearch.indexOf('托盘号') != -1">
                            托盘号：<input type="text" id="carrierId" name="carrierId"/>
                        </li>
                        <li v-if="checkedSearch.indexOf('SAP交货单号') != -1">
                            SAP交货单号：<input type="text" id="billNo" name="billNo"/>
                        </li>
                        <li v-if="checkedSearch.indexOf('批次号') != -1">
                            批次号：<input type="text" id="materialBatchId" name="materialBatchId"/>
                        </li>
                        <li v-if="checkedSearch.indexOf('收货状态') != -1">
                            收货状态：
                            <select name="state">
                                <option value="">全部</option>
                                <option value="1">待入库</option>
                                <option value="2">部分入库</option>
                                <option value="3">入库完成</option>
                                <option value="4">过账完成</option>
                                <option value="5">过账上传中</option>
                                <option value="6">过账失败</option>
                            </select>
                        </li>
                        <li v-if="checkedSearch.indexOf('单晶规格') != -1">
                            单晶规格：
                            <select name="specId">
                                <option value="">全部</option>
                                <option value="G12">G12</option>
                                <option value="M6">M6</option>
                            </select>
                        </li>
                        <li v-if="checkedSearch.indexOf('单晶PN型') != -1">
                            单晶PN型：
                            <select name="materialPN">
                                <option value="">全部</option>
                                <option value="P">P</option>
                                <option value="N">N</option>
                            </select>
                        </li>
                        <li v-if="checkedSearch.indexOf('拼棒类型') != -1">
                            拼棒类型：
                            <select name="assemblyType">
                                <option value="">全部</option>
                                <option value="1">整棒</option>
                                <option value="2">二拼</option>
                                <option value="3">三拼</option>
                            </select>
                        </li>
                        <li v-if="checkedSearch.indexOf('操作员') != -1">
                            操作员：
                            <input type="hidden" id="createUserName" name="createUserName" v-model="checkCreateUserName"/>
                            <el-select multiple collapse-tags v-model="checkCreateUserList" @change="changeSelect" placeholder="请选择操作员">
                                <el-checkbox v-model="allCheckCreateUser" @change="selectAll" style="margin-left: 10px;padding: 5px 0">全选</el-checkbox>
                                <el-option v-for="(item, index) in users" :key="index" :label="item.userName" :value="item.userId"></el-option>
                            </el-select>
                        </li>
                        <li v-show="checkedSearch.indexOf('入库建单时间') != -1">
                            <label>入库建单时间：</label>
                            <el-date-picker
                                name="startTime"
                                v-model="timeA"
                                value-format="yyyy-MM-dd HH:mm:ss"
                                type="datetime"
                                @change="compareAB"
                                placeholder="开始时间">
                            </el-date-picker>
                            <span>-</span>
                            <el-date-picker
                                name="endTime"
                                v-model="timeB"
                                value-format="yyyy-MM-dd HH:mm:ss"
                                type="datetime"
                                @change="compareAB"
                                placeholder="结束时间">
                            </el-date-picker>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()" @click="myReset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            <a class="btn btn-success btn-rounded btn-sm" @click="moreSearch()"><i class="fa fa-edit"></i>&nbsp;更多</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>
        <el-dialog title="搜索条件" width="200px" :visible.sync="showMore">
            <el-row>
                <el-col :span="24">
                    <el-checkbox style="margin-left: 28px" :indeterminate="isIndeterminate" v-model="checkAll" @change="handleCheckAllChange">全选</el-checkbox>
                    <el-checkbox-group v-model="checkedSearch" @change="handleCheckedSearchChange">
                        <el-checkbox style="display: block;margin-left: 28px" v-for="item in searches" :label="item" :key="item" v-cloak>{{item}}</el-checkbox>
                    </el-checkbox-group>
                </el-col>
            </el-row>
        </el-dialog>
        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="in:MaterialInfo:export">
                <i class="fa fa-download"></i> 导出全部
            </a>
            <a class="btn btn-info" @click="partExcel()" shiro:hasPermission="in:MaterialInfo:partExcel">
                <i class="fa fa-download"></i> 部分导出
            </a>
            <a class="btn btn-primary" onclick="$.table.print()">
                <i class="fa fa-plus"></i> 打印
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true" style="white-space: nowrap"></table>
        </div>
    </div>
</div>

<div th:include="include :: footer"></div>
<script th:src="@{/wms/js/moreSearch.js}"></script>
<script th:inline="javascript">
    var prefix = ctx + "in/MaterialInfo";

    const searchOptions = ['托盘号', 'SAP交货单号', '批次号', '收货状态', '单晶规格', '单晶PN型', '拼棒类型', '操作员', '入库建单时间'];

    var app = new Vue({
        el: '.container-div',
        data: {
            showMore: false,
            checkAll: false,
            checkedSearch: ['托盘号', 'SAP交货单号', '批次号', '收货状态', '操作员', '入库建单时间'],
            searches: searchOptions,
            isIndeterminate: true,
            timeA: '',
            timeB: '',
            users: [],
            checkCreateUserList: [],
            allCheckCreateUser: false,
            checkCreateUserName: ''
        },
        methods: {
            //时间对比
            compareAB: function(){
                if(this.timeA != '' && this.timeA != null){
                    if(this.timeB != '' && this.timeB != null){
                        var a = new Date(this.timeA);
                        var b = new Date(this.timeB);
                        if(a > b){
                            $.modal.alertError("结束时间需大于开始时间，请重新选择！！");
                            this.timeA = '';
                            this.timeB = '';
                        }
                    }else{
                        this.timeB = '';
                    }
                }else{
                    this.timeA = '';
                    if(this.timeB == null){
                        this.timeB = '';
                    }
                }
            },
            //获取操作员列表
            getUsers(){
                var that = this;
                $.ajax({
                    cache: true,
                    type: "POST",
                    url: "/system/user/list",
                    data: {},
                    async: false,
                    error: function(request){
                        $.modal.alertError("系统错误");
                    },
                    success: function(data){
                        that.users = data.rows;
                    }
                });
            },
            //操作员下拉框全选
            selectAll(){
                this.checkCreateUserList = []
                if(this.allCheckCreateUser){
                    var tmpArr = [];
                    this.users.forEach((item) => {
                        tmpArr.push(item.userName);
                    })
                    this.checkCreateUserList = tmpArr;
                    this.checkCreateUserName = this.checkCreateUserList.toString();
                }else{
                    this.checkCreateUserList = [];
                    this.checkCreateUserName = '';
                }
            },
            //切换操作员全选状态
            changeSelect(val){
                if(val.length == this.users.length) {
                    this.allCheckCreateUser = true;
                }else{
                    this.allCheckCreateUser = false;
                }
                this.checkCreateUserName = this.checkCreateUserList.toString();
            },
            //清空操作员
            resetCheckCreateUserName(){
                this.checkCreateUserList = [];
                this.checkCreateUserName = '';
            },
            //清空时间
            resetTime(){
                this.timeA = '';
                this.timeB = '';
            },
            //重置按钮
            myReset(){
                this.resetCheckCreateUserName();
                this.resetTime();
            },
            //今天日期
            today(){
                var date = new Date();
                var Y = date.getFullYear() + '-';
                var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
                var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
                return Y + M + D;
            },
            //部分导出
            partExcel(){
                var rows = $.common.isEmpty($.table._option.uniqueId) ? $.table.selectColumns("carrierId") : $.table.selectColumns($.table._option.uniqueId);
                if(rows.length == 0){
                    $.modal.alertWarning("请至少选择一条记录");
                    return;
                }else{
                    $.modal.confirm("确认要导出选中的" + rows.length + "条数据吗?", function(){
                        var url = prefix + "/partExcel";
                        var data = {"ids": rows.join()};
                        $.post(url, data, function(result){
                            if(result.code == web_status.SUCCESS){
                                window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
                            }else if(result.code == web_status.WARNING){
                                $.modal.alertWarning(result.msg);
                            }else{
                                $.modal.alertError(result.msg);
                            }
                            $.modal.closeLoading();
                        });
                    });
                }
            }
        },
        created(){
            this.getUsers();
            this.timeA = this.today() + " 00:00:00";
            this.timeB = this.today() + " 23:59:59";
        }
    })

    $(function() {
        var options = {
            url: prefix + "/findList",
            exportUrl: prefix + "/export",
            detailUrl: prefix + "/detail",
            modalName: "晶棒托入库",
            queryParams: queryParams,
            columns: [
                {
                    checkbox: true
                },
                {
                    title: '序号',
                    align: 'center',
                    formatter: function(value, row, index){
                        return index + 1;
                    },
                    visible: false
                },
                {
                    field: 'carrierId',
                    title: '托盘号',
                    align: 'center'
                },
                {
                    field: 'billNo',
                    title: 'SAP交货单号',
                    align: 'center'
                },
                {
                    field: 'materialBatchId',
                    title: '批次号',
                    align: 'center'
                },
                {
                    title: '物料名称',
                    align: 'center',
                    formatter: function(value, row, index){
                        return '单晶方棒';
                    }
                },
                {
                    field: 'state',
                    title: '收货状态',
                    align: 'center',
                    formatter: function(value, row, index){
                        var actions = [];
                        if(value == 1 || value == null){
                            actions.push("<span class='tag' style='background-color: #999999'>待入库</span>");
                        }else if(value == 2){
                            actions.push("<span class='tag' style='background-color: #f8ac59'>部分入库</span>");
                        }else if(value == 3){
                            actions.push("<span class='tag' style='background-color: #1ab394'>入库完成</span>");
                        }else if(value == 4){
                            actions.push("<span class='tag' style='background-color: #1ab394'>过账完成</span>");
                        }else if(value == 5){
                            actions.push("<span class='tag' style='background-color: #f8ac59'>过账上传中</span>");
                        }else if(value == 6){
                            actions.push("<span class='tag' style='background-color: #ed5565'>过账失败</span>");
                        }
                        return actions.join('');
                    }
                },
                {
                    field: 'specId',
                    title: '单晶规格',
                    align: 'center'
                },
                {
                    field: 'materialPN',
                    title: '单晶PN型',
                    align: 'center'
                },
                {
                    field: 'assemblyType',
                    title: '拼棒类型',
                    align: 'center',
                    formatter: function(value, item, index){
                        var actions = [];
                        if(value == 1){
                            actions.push("<span class='tag' style='background-color: #fcb529'>整棒</span>");
                        }else if(value == 2){
                            actions.push("<span class='tag' style='background-color: #45ade1'>二拼</span>");
                        }else if(value == 3){
                            actions.push("<span class='tag' style='background-color: #45ade1'>三拼</span>");
                        }
                        return actions.join('');
                    }
                },
                {
                    field: 'resistance',
                    title: '电阻率',
                    align: 'center'
                },
                {
                    field: 'totalLength',
                    title: '合计长度（mm）',
                    align: 'center'
                },
                {
                    field: 'totalWeight',
                    title: '合计重量（kg）',
                    align: 'center'
                },
                {
                    field: 'createUserName',
                    title: '操作员',
                    align: 'center'
                },
                {
                    field: 'createTime',
                    title: '入库建单时间',
                    align: 'center',
                    formatter: function(value, item, index){
                        if(value == null){
                            return '-';
                        }else{
                            return value.slice(0, 19);
                        }
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    events: {
                        'click .detail': function(e, value, rowData, index){
                            var id = rowData.carrierId;
                            var _url = $.table._option.detailUrl;
                            localStorage.setItem(_url, id.toString());
                            open("晶棒托详情", _url, '1600', '700', null);
                        }
                    },
                    formatter: function(value, row, index){
                        var actions = [];
                        actions.push("<span class='detail tag' style='background-color: #3097b5;cursor: pointer'><i class='fa fa-hand-pointer-o'></i> 查看</span>");
                        return actions.join('');
                    }
                }
            ]
        };
        $.table.init(options);
    });

    function queryParams(params){
        return {
            pageSize: params.limit,
            pageNum: params.offset / params.limit + 1,
            orderByColumn: params.sort,
            isAsc: params.order,
            startTime: app.timeA,
            endTime: app.timeB
        };
    }

    function open(title, url, width, height, callback){
        if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){
            width = 'auto';
            height = 'auto';
        }
        if($.common.isEmpty(title)){
            title = false;
        }
        if($.common.isEmpty(url)){
            url = "/404.html";
        }
        if($.common.isEmpty(width)){
            width = 800;
        }
        if($.common.isEmpty(height)){
            height = ($(window).height() - 250);
        }
        if($.common.isEmpty(callback)){
            callback = function(index, layero){
                var iframeWin = layero.find('iframe')[0];
                iframeWin.contentWindow.submitHandler();
            }
        }
        layer.open({
            type: 2,
            area: [width + 'px', height + 'px'],
            fix: false,
            maxmin: true,
            shade: 0.3,
            title: title,
            content: url,
            btn: ['关闭'],
            shadeClose: true,
            cancel: function(index){
                return true;
            }
        });
    }
</script>
</body>
</html>
